package com.example.battle.handler;

import com.example.battle.entity.sys.Account;
import com.example.battle.repository.AccountRepository;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Data
@Slf4j
@Component
public class AccountMessage {
    public static AccountMessage accountMessage;
    @Autowired
    private AccountRepository accountRepository;

    private String userId;
    private String avatarUrl;
    private String nickName;
    private String city;
    private String province;

    public AccountMessage() {
    }
    @PostConstruct
    public void init() {
        accountMessage = this;
        accountMessage.accountRepository = this.accountRepository;
    }

    public void set(String userId, String avatarUrl){
        this.userId = userId;
        this.avatarUrl = avatarUrl;
        Account account = accountMessage.accountRepository.findByAvatarUrl(avatarUrl);
        this.nickName = account.getNickName();
        this.province = account.getProvince();
        this.city = account.getCity();
    }
}
